def template = """
    <div class="col-sm-3">
        <div class="xe-widget xe-conversations box2 label-info" onclick="window.open('T_URL', '_blank')" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="T_URL">
            <div class="xe-comment-entry">
                <a class="xe-user-img">
                    <img src="T_LOGO" class="lozad img-circle" width="40">
                </a>
                <div class="xe-comment">
                    <a href="#" class="xe-user-name overflowClip_1">
                        <strong>T_NAME</strong>
                    </a>
                    <p class="overflowClip_2">T_DESC</p>
                </div>
            </div>
        </div>
    </div>
"""

def sites = new File('./micrograils.sites').text.trim()

def sb = '<div class="row">'
sites.split('\n').each {
    if ( it.startsWith('#') ) return
    if ( it.trim().size() == 0 ) {
        sb += '</div><div class="row">'
    }
    def site = it.trim().split('\\|')
    if (site.size() > 1) {
        def html = template.replaceAll('T_URL', site[0])
        html = html.replace('T_NAME', site[1])
        html = html.replace('T_LOGO', site.size() > 2 ? (site[2].startsWith('http') ? site[2] : '../micrograils/images/' + site[2]) : '../micrograils/images/micrograils.png')
        html = html.replace('T_DESC', site.size() > 3 ? site[3] : '这个家伙很懒~')
        sb += html
    }
}
sb += '</div>'

new File('./micrograils.html').write(sb, 'utf-8')
